MySQL BLOB 和 TEXT,主要内容有:
- 起因介绍:一个 5.7.18 版本的 insert …… on duplicate 与 TEXT & BLOB 相关 bug
 - TEXT & BLOB 相同点
 - TEXT & BLOB 不同点
 
BLOB 和 TEXT
起因是一个 BUG:在 percona 5.7.18 版本中,在 insert …… on duplicated 下包含 text 字段有可能导致实例重启,具体的bug
故想看下 BLOB 和 TEXT 在日常中的区别。参考的主要是官方文档:The BLOB and TEXT Types,其中:
共同的坑:
- 包含 TEXT or BLOG 且用到了 
temporary table的情况,会导致temporary table实际使用的是 on-disk 而不是 in-memory,可以通过参数 Created_tmp_disk_tables 来验证。细节参考 Internal Temporary Table Use in MySQL - 没有默认值
 - 最大的长度其实会受限于:max_allowed_packet,并且这个值在 client 端和 server 端其实是都有的
 - 当你想要对 BLOB 和 TEXT 创建索引的时候,必须指定索引的长度
 - 排序的时候,只会用到 
max_sort_length指定长度的内容 
不同的地方:
- 排序不同:BLOB 是根据 numeric values of the bytes 排序,TEXT 是字符串顺序
 - strict SQL mode 对 BLOB 和 TEXT 的截断操作不一样:超出 column 的 max_len
 
btw,如果测试的时候插入 BLOB,可以参考:如何插入BLOB